<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>登录</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <meta name="description" content="登陆界面" />
    <meta name="author" content="tengshe789" />
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css" th:href="@{/bootstrap/css/bootstrap.css}" />
    <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/css/signin.css}" />
    <!-- jquery-validator -->
    <script type="text/javascript" th:src="@{/jquery-validation/jquery.validate.min.js}"></script>
    <script type="text/javascript" th:src="@{/jquery-validation/localization/messages_zh.min.js}"></script>
    <!-- layer -->
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <!-- md5.js -->
    <script type="text/javascript" th:src="@{/js/md5.min.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/js/common.js}"></script>

</head>
<body>

<form class="form-signin" name="loginForm" id="loginForm" method="post">
    <img class="mb-5 .col-md-offset-2" th:src="@{/home.svg}" alt="" width="100% \9" height="72" />
    <h1 class="h3 mb-3 font-weight-normal" align="center">请您登陆</h1>
    <label for="mobile" class="sr-only">请输入手机号码</label>
    <input type="text" id="mobile"  name = "mobile" class="form-control" placeholder="手机号码" required="true" autofocus="true" minlength="11" maxlength="11" />
    <label for="password" class="sr-only">请输入密码</label>
    <input type="password" name="password" id="password" class="form-control" placeholder="密码" required="true" minlength="6" maxlength="16" />
    <div class="checkbox mb-3" align="center">
        <label>
            <button type="reset" value="remember-me" onclick="reset()"> 重置</button>
        </label>
    </div>
    <button class="btn btn-lg btn-primary btn-block" type="submit" onclick="login()">登录</button>
    <p class="mt-5 mb-3 text-muted" align="center">&copy; 2018-2019</p>

</form>
</body>
<script>
    function login(){
        $("#loginForm").validate({
            submitHandler:function(form){
                doLogin();
            }
        });
    }
    function doLogin(){
        g_showLoading();
        var inputPass = $("#password").val();
        var salt = g_passsword_salt;
        var str = ""+salt.charAt(0)+salt.charAt(2) + inputPass +salt.charAt(5) + salt.charAt(4);
        var password = md5(str);
        $.ajax({
            url: "/login/do_login",
            type: "POST",
            data:{
                mobile:$("#mobile").val(),
                password: password
            },
            success:function(data){
                layer.closeAll();
                if(data.code == 0){
                    layer.msg("成功");
                    window.location.href="/goods/to_list";
                }else{
                    layer.msg(data.msg);
                }
            },
            error:function(){
                layer.closeAll();
            }
        });
    }
</script>
</html>